package com.blog.annotation;

import com.blog.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 操作日志记录处理
 *
 * @author ruoyi
 */
@Aspect
@Component
public class OperationLogAspect {



    /**
     * 处理完请求后执行
     *
     * @param joinPoint 切点
     */
    @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult")
    public void doAfterReturning(JoinPoint joinPoint, OperationLog controllerLog, Object jsonResult)
    {
        handleLog(joinPoint, controllerLog, null, jsonResult);
    }

    /**
     *
     * @param
     * @return
     */
    private void handleLog(JoinPoint joinPoint, OperationLog controllerLog, Object o, Object jsonResult) {
        try {
            //获取操作人信息
            Subject subject = SecurityUtils.getSubject();
            SysUser sysUser = (SysUser) subject.getPrincipal();



            System.out.println(sysUser);
            System.out.println(joinPoint);
            System.out.println(controllerLog);
            System.out.println(o);
            System.out.println(jsonResult);

        }catch (Exception e){

        }
    }
}
